import sys
from PyQt5.QtWidgets import QApplication
from desktop_app.controllers.auth_client import AuthClient
from desktop_app.views.login_window import LoginWindow
from desktop_app.controllers.api_client import ApiClient
from desktop_app.views.main_window import MainWindow

class AppManager:
    def __init__(self):
        self.app = QApplication(sys.argv)
        self.auth_client = AuthClient()
        self.api_client = ApiClient()
        self.login_window = LoginWindow(self.auth_client)
        self.main_window = None
        
        # 连接登录成功信号
        self.auth_client.login_success.connect(self.show_main_window)
        
    def show_main_window(self, user_data):
        self.main_window = MainWindow(self.api_client)
        self.main_window.show()
        
    def run(self):
        self.login_window.show()
        sys.exit(self.app.exec_())

if __name__ == '__main__':
    manager = AppManager()
    manager.run()